//
//  CZVisitorTableViewController.swift
//  WH01
//
//  Created by Apple on 16/7/8.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit
//  访客视图控制器
class CZVisitorTableViewController: UITableViewController {

    //  是否登录标记
    var isLogin: Bool = false
    //  访客视图
    var vistorView: CZVistorView?
    override func loadView() {
        if isLogin {
            //  如果登录我们使用系统提供的视图
            super.loadView()
            
            
            
            
        } else {
            //  没有登录我们使用自定义视图
            
            vistorView = CZVistorView()
            
            //  使用self需要注意循环引用
            vistorView?.loginClosure = { [weak self] in
                //  
                print("点击了 访客视图里面登录或者注册")
                self?.showOAuthVC()
            }
            
            view = vistorView
            setupUI()
        }
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    
    private func setupUI() {
        setupNavUI()
    }
    
    private func setupNavUI() {
    
       
        //  设置自定义视图
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginAction")
    
    
    
    
    }
    
    // MARK:    点击事件
    
    @objc private func registerAction() {
        print("registerAction")
        showOAuthVC()
    }
    
    @objc private func loginAction() {
        print("loginAction")
        showOAuthVC()
    }
    
    
    private func showOAuthVC() {
        let oAuthVC = CZOAuthViewController()
        let oAtuthNav = UINavigationController(rootViewController: oAuthVC)
        presentViewController(oAtuthNav, animated: true, completion: nil)
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
}
